#incoding=utf-8
from django.db import models
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType

# Create your models here.
    
class Image(models.Model):
    image = models.ImageField(upload_to='images')
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey("content_type", "object_id")
    describe = models.CharField(max_length=300, blank=True, null=True)

class Product(models.Model):
    name = models.CharField(max_length=100)

from django.contrib import admin
from pydemo.imgupload.models import Image, Product

class ImageInline(generic.GenericTabularInline):
    model = Image
    list_display=('image','describe')
    
class PorductAdmin(admin.ModelAdmin):
    list_display=('id', 'name')
    inlines = [ImageInline, ]

    
admin.site.register(Product, PorductAdmin)